package pandabay.domain;

import java.util.*;


public class Auction {
	private Product product;
	private User highestBidder;
	private User seller;
	private double startPrice;
	private ArrayList<Double> bids;
	private Date startDate;
	private Date endDate;
	/*
	 * constructor
	 */
	public Auction(Product product, User seller, double startPrice, Date startDate, Date endDate){
		this.product = product;
		this.seller = seller;
		this.startPrice = startPrice;
		this.startDate = startDate;
		this.endDate = endDate;
	}
	
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString(){
		return this.product + " " + this.highestBidder + " " + this.seller + " " + this.startPrice + " " + this.bids.toString() +
				" " + this.startDate + " " + this.endDate;
	}
	
	/*
	 * @return the amount of bids
	 */
	public int countBids(){
		
		return bids.size();
	}
	
	
	/*
	 * @return the highest bid of a product
	 */
	public double highestBid(){
		double pivot = startPrice;
		for (int i=0;i<bids.size();i++){
			try{
				if (bids.get(i)>pivot){
					pivot = bids.get(i);
					}
				}catch(IndexOutOfBoundsException e){
					System.out.println("unpossible to find highest bid due to array out of bounds exception!");
				}
			}
		return pivot;
	}
	
	
	//getters and setters
	/**
	 * @return the product
	 */
	public Product getProduct() {
		return product;
	}
	/**
	 * @param product the product to set
	 */
	public void setProduct(Product product) {
		this.product = product;
	}
	/**
	 * @return the highestBidder
	 */
	public User getHighestBidder() {
		return highestBidder;
	}
	/**
	 * @param highestBidder the highestBidder to set
	 */
	public void setHighestBidder(User highestBidder) {
		this.highestBidder = highestBidder;
	}
	/**
	 * @return the seller
	 */
	public User getSeller() {
		return seller;
	}
	/**
	 * @param seller the seller to set
	 */
	public void setSeller(User seller) {
		this.seller = seller;
	}
	/**
	 * @return the startPrice
	 */
	public double getStartPrice() {
		return startPrice;
	}
	/**
	 * @param startPrice the startPrice to set
	 */
	public void setStartPrice(double startPrice) {
		this.startPrice = startPrice;
	}
	/**
	 * @return the bids
	 */
	public ArrayList<Double> getBids() {
		return bids;
	}
	/**
	 * @param bids the bids to set
	 */
	public void setBids(ArrayList<Double> bids) {
		this.bids = bids;
	}
	/**
	 * @return the startDate
	 */
	public Date getStartDate() {
		return startDate;
	}
	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	/**
	 * @return the endDate
	 */
	public Date getEndDate() {
		return endDate;
	}
	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	
}
